<?php
function generateWsdl($serviceName, $className, $serviceUrl) {
    $reflector = new ReflectionClass($className);
    $methods = $reflector->getMethods(ReflectionMethod::IS_PUBLIC);

    $wsdl = "<?xml version=\"1.0\"?>\n";
    $wsdl .= "<definitions name=\"$serviceName\" targetNamespace=\"$serviceUrl\"\n";
    $wsdl .= "xmlns:tns=\"$serviceUrl\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\"\n";
    $wsdl .= "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\">\n";

    // 根据类中的方法生成 WSDL 中的操作描述
    foreach ($methods as $method) {
        $wsdl .= "  <wsdl:operation name=\"{$method->name}\">\n";
        $wsdl .= "    <soap:operation soapAction=\"$serviceUrl#{$method->name}\" />\n";
        $wsdl .= "  </wsdl:operation>\n";
    }
    $wsdl .= "</definitions>\n";

    return $wsdl;
}

header("Content-Type: application/xml");
echo generateWsdl("CalculatorService", "App\\Services\\CalculatorService", "http://yourdomain.com/soap-server.php");